home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 07 (1988)(MegaDisc Digital Publishing)(AU)[WB].zip / MegaDisc 07 (1988)(MegaDisc Digital Publishing)(AU)[WB].adf / ARTICLES / Gfx_Prog < prev    next >
Text File  |  2000-04-10  |  31KB  |  602 lines

  1.  
  2. Programming Amiga Graphics
  3.  
  4. O‚v‚e‚r‚v‚i‚e‚w‚
  5.  
  6.  This article describes the graphics capabilities of the Amiga, both in
  7.  terms of the data structures and ROM Kernel routines which allow the
  8.  programmer to control the Amiga's display, and the custom graphics
  9.  circuitry which enables the system to create the displays requested by
  10.  the programmer. Although it is intended to give a prospective
  11.  programmer sufficient information (along with the appropriate Reference
  12.  Manuals) to tackle most facets of Amiga graphics programming, this
  13.  article concentrates on providing a conceptual understanding of the
  14.  interrelationships between various components of the graphics system. It
  15.  can therefore be read be profitably read by any Amiga user who wishes to
  16.  gain an insight into the workings of the Amiga's remarkable graphics.
  17.  
  18.  Amiga graphics may be approached on three levels by the programmer, which
  19.  I shall call -
  20.     1. Intuition
  21.     2. Kernel
  22.     3. Copper
  23.  These names are purely of my choice, and may conflict with those chosen
  24.  by others for the same purpose.
  25.  
  26. Intuition  is the name of the Amiga's user interface (which
  27.  includes screens,windows,menus etc), but I also use it to refer to a set
  28.  of data structures and routines which are designed to give the programmer
  29.  the easiest possible access to graphics while remaining within the
  30.  confines of the Intuition user interface. Intuition is designed to allow
  31.  the user to make effective use of the Amiga's multitasking capabilities,
  32.  so programs intending to co-operate with Intuition should restrict
  33.  themselves to Intuition-level graphics where possible. Although facilities
  34.  available at the Kernel and Copper levels may be used by such programs,
  35.  care must be taken that the Intuition interface is not destroyed by their
  36.  use.
  37.  
  38. Kernel is shorthand for "ROM Kernel", which is commonly used to
  39.  describe the routines in ROM which form the major part of the Amiga's
  40.  operating system. While some of the graphics routines in ROM support
  41.  Intuition-level graphics, the majority allow the user to control the
  42.  Amiga's graphics with more flexibility and provide the programmer with
  43.  much more power. The use of some Kernel-level features precludes the
  44.  existence (or at least availability to the user) of the Intuition
  45.  interface, hence programs which use these facilities are often referred
  46.  to as "nasty" or as "taking over the machine".
  47.  Kernel graphics allows the programmer to exercise very close control over
  48.  the appearance of the Amiga's display, providing easy access to the
  49.  capabilities of the graphics hardware; it generally provides the optimum
  50.  environment as regards simplicity, flexibility and speed of operation.
  51.  
  52. Copper is short for "Coprocessor", a simple microprocessor contained
  53.  in one of the custom chips which directly controls the Amiga's video
  54.  display using a list of simple instructions which form a rudimentary
  55.  "program". While this list is normally created and maintained by Kernel
  56.  routines, it is possible for the programmer to create a Copper list
  57.  directly - i.e. Copper-level programming. While more laborious and
  58.  complex than Kernel-level programming, Copper programming provides the
  59.  maximum possible control over the Amiga's graphics, making possible
  60.  effects and animations unobtainable with Kernel programming.
  61.  The Kernel provides a mechanism for safely integrating Copper programs
  62.  into Kernel or even Intuition displays; this will be discussed in
  63.  conjunction with direct Copper control.
  64.  
  65.  Note that the distinctions between these "levels" of programming are
  66.  somewhat blurred - the Intuition interface is built directly on the
  67.  Kernel routines and structures, and the Kernel relies, ultimately, on
  68.  the Copper to create your display.
  69.  
  70.  The material from here on becomes more technically detailed. If you are
  71.  not familiar with such concepts as "data structures","routines" and
  72.  "pointers" please read Appendix A. The concepts explained there are
  73.  fundamental to the rest of this article.
  74.  
  75. A‚m‚i‚g‚a‚ ‚G‚r‚a‚p‚h‚i‚c‚s‚ ‚F‚u‚n‚d‚a‚m‚e‚n‚t‚a‚l‚s‚
  76.  
  77.  To draw and display graphics on the Amiga, the first requirement is
  78.  that you have a block of screen memory of the appropriate size
  79.  to work with. This memory block may be anywhere in the lowest-addressed
  80.  512 Kbytes of the Amiga's memory. Since the operating system maintains
  81.  internally a list of memory blocks which are free (i.e. not in use by
  82.  any other tasks running in the system), you should call one of the
  83.  memory-allocations routines to have the system allocate to you a block
  84.  of screen memory of the size you require. The routine
  85.  AllocRaster is designed specifically for allocating screen
  86.  memory, and returns the address of a block of memory of the size you
  87.  specify which you may safely use.
  88.  
  89.  This screen memory is organised, from the programmer's point of view,
  90.  as a rectangular "bit plane", which has a width and height (in pixels)
  91.  specified by you. The first bit of the memory block is the upper left
  92.  corner pixel of the rectangle, while the last bit is the lower right
  93.  corner pixel; the leftmost pixel of each line and the rightmost of the
  94.  previous line correspond to adjacent bits in your memory block. It is
  95.  apparent that a given memory block may serve as a bit plane of any width
  96.  and height, provided the overall area remains the same.
  97.  
  98.  If you wish to display more than two colours in your graphics region
  99.  you must allocate memory for more than one bit plane. Imagine that these
  100.  planes are directly overlaid on each other; the colour of each pixel is
  101.  determined by the combination of the corresponding bits in each
  102.  bit-plane. Each plane you use doubles the number of available colours,
  103.  up to a limit of 6 planes (see Graphics Modes). Since these planes are
  104.  conventionally numbered from zero upward, each pixel in the region can
  105.  have a "colour number" ranging from 0 to an upper limit determined by
  106.  the number of bit planes used. The means by which the colour number of
  107.  a pixel determines the displayed colour is explained in Graphics Modes
  108.  and Colours.
  109.  The combination of a number of bit planes of given width and height is
  110.  known as a "bit map", and is described by a data structure called a
  111.  "BitMap". This structure specifies the number of bytes in each row
  112.  (horizontal line) of the bit map (there are eight bits or pixels in one
  113.  byte), the height of the bit map in screen lines and the number of
  114.  planes used (or "depth"). It also contains a pointer to each bit plane.
  115.  
  116.  Note that a bit map has maximum dimensions of 1024 by 1024 pixels.
  117.  
  118.  
  119. R‚e‚n‚d‚e‚r‚i‚n‚g‚ ‚v‚e‚r‚s‚u‚s‚ ‚D‚i‚s‚p‚l‚a‚y‚i‚n‚g‚
  120.  
  121.  The facilities provided by any computer's graphics system may be, in
  122.  general, divided into "Rendering" and "Displaying". Rendering into a
  123.  bit map is the act of modifying its pixels, either singly or in groups.
  124.  It is important to understand that on the Amiga there is no requirement
  125.  that the bit map you render into be visible on the screen, or that a
  126.  bit map you display has been  rendered into. The rendering and
  127.  displaying mechanisms are entirely separate, and the relationship
  128.  between what is rendered and what is visible on the screen is entirely
  129.  under the control of the programmer. The only common point of both
  130.  mechanisms is the BitMap structure, which is used for both rendering
  131.  and display.
  132.  
  133.  
  134. G‚r‚a‚p‚h‚i‚c‚s‚ ‚R‚e‚n‚d‚e‚r‚i‚n‚g‚
  135.  We shall deal with graphics rendering first, since rendering into a
  136.  bitmap is much simpler and more straightforward than displaying it.
  137.  
  138.  There are two structures used to control the rendering process - the
  139.  BitMap (described above) and the "RastPort". The RastPort contains a
  140.  large amount of information which determines how rendering into the
  141.  BitMap (to which the RastPort must point) will be performed.
  142.  "Foreground", "Background" and "Outline" pen colours determine the
  143.  colours used to render lines, rectangles, text etc. and affect
  144.  area-filling operations. Line and area patterns are stored in the
  145.  RastPort, as are the characteristics (font, spacing etc.) of text
  146.  rendered. The Kernel routine InitRastPort is used to
  147.  initialise the RastPort's fields to useful default values.
  148.  The Kernel provides a large number of routines for graphics rendering,
  149.  most of which require the address of a RastPort. These include routines
  150.  to set the foreground, background and outline colours, and draw lines,
  151.  outline and filled polygons, filled rectangles, ellipses and circles
  152.  in the current foreground colour and line and area patterns. Also
  153.  provided are routines to draw text into the bitmap and move rectangular
  154.  blocks of pixels from one bit map to another.
  155.  
  156.  
  157. G‚r‚a‚p‚h‚i‚c‚s‚ ‚D‚i‚s‚p‚l‚a‚y‚i‚n‚g‚
  158. G‚r‚a‚p‚h‚i‚c‚s‚ ‚M‚o‚d‚e‚s‚ ‚a‚n‚d‚ ‚C‚o‚l‚o‚u‚r‚s‚
  159.  
  160.  The programmer has a number of choices as to how a given bit map may
  161.  be displayed. He may select:
  162.  - low or high resolution (320 or 640 pixels per line respectively);
  163.  - non-interlaced or interlaced display (200 or 400 screen lines);
  164.  - one of several "special" modes, namely HAM (Hold and Modify), extra
  165.    half bright, genlock video and dual playfield. Each of these modes may
  166.    be applied to the whole screen or a selected portion of it.
  167.  
  168.  If no special display mode is selected, the colour which will be
  169.  displayed on the screen for each pixel of the bit map is determined by
  170.  its colour number and the corresponding entry in the "colour palette",
  171.  an array which contains the actual red, green and blue intensities of
  172.  the screen colour which is displayed for each colour number. This
  173.  palette can have a maximum  of 32 entries, which is fully utilized by
  174.  the low-resolution display of a 5 plane bit map. However, a
  175.  high-resolution display may only use a 4 plane bitmap.
  176.  
  177.  Some of the special graphics modes can use 6 bit planes, for example HAM
  178.  and dual-playfield. However, these do not directly use the colour palette
  179.  to generate displays.
  180.  
  181.  The following sections describe the three "levels" at which graphics may
  182.  be displayed - Kernel, Intuition and Copper. We shall begin with Kernel
  183.  graphics, since this knowledge provides the best basis for understanding
  184.  the rest.
  185.  
  186. K‚e‚r‚n‚e‚l‚ ‚G‚r‚a‚p‚h‚i‚c‚s‚
  187.  The appearance of the Amiga's screen is described by a group of data
  188.  structures which are created and manipulated by the programmer. These
  189.  structures are used by Kernel routines to create the displays desired
  190.  by the programmer.
  191.  
  192.  Variables affecting the entire screen are stored in the "View" structure.
  193.  These are:
  194.  - the offset of the top left corner of the visible screen area from a
  195.    defined position, allowing the display as a whole to be easily moved;
  196.  - the addresses of the hardware copper lists for the display
  197.    (see Copper Graphics);
  198.  - flags describing various display parameters;
  199.  - a pointer to a ViewPort structure (see below).
  200.  
  201.  The screen display created by use of the View structure is also termed
  202.  a "view".
  203.  
  204.  The Amiga's screen can be subdivided into any number of horizontal
  205.  slices (at least one must be present) known as "viewports", each of which
  206.  is described by a ViewPort structure. This structure contains:
  207.  - the width and height of the viewport in pixels;
  208.  - the offset in pixels of the top left corner of the viewport from the
  209.    top left corner of the view;
  210.  - a pointer to a "RasInfo" structure (to be discussed below), which
  211.    contains information about the bit map to be displayed in this viewport;
  212.  - a pointer to a colour map. The colour map is a structure which contains
  213.    a palette and related information;
  214.  - flags indicating the graphics modes to be used in this viewport (as
  215.    described in Graphics Modes);
  216.  - pointers to user and system intermediate copper lists (see Copper
  217.    Graphics);
  218.  - a pointer to the next viewport in the view, which is zero of this is
  219.    the last.
  220.  Note that the viewports must not overlap, and a gap of one to three
  221.  screen lines, depending on the graphics modes used in each viewport,
  222.  must be left between them.
  223.  
  224.  Each ViewPort points to a RasInfo structure, which contains the
  225.  following information:
  226.  - a pointer to a BitMap structure which describes the bit map to be
  227.    displayed in this viewport;
  228.  - the offset of the top left corner of the rectangular region displayed
  229.    in the viewport from the top left corner of the bit map. By changing
  230.    this offset you can easily display different portions of a bit map
  231.    too large to fit on the screen, for example to smoothly scroll a game
  232.    background across the screen.
  233.  - a pointer to another RasInfo structure, required when the dual
  234.    playfield graphics mode is used for this viewport.
  235.  
  236.  In summary, then, the Kernel data structures needed to create a full
  237.  display are:
  238.  - View : describes the screen as a whole, points to first ViewPort;
  239.  - ViewPort : describes a horizontal slice of the screen;
  240.  - RasInfo : describes the region to be displayed;
  241.  - BitMap : describes the bit map containing the region to be displayed.
  242.  A typical display containing three viewports, the second of which uses
  243.  dual-playfield mode, would require the following structures to be set
  244.  up by the programmer:
  245.                      ( -> indicates "points to")
  246.       View
  247.        |
  248.        V
  249.     ViewPort -> ColorMap
  250.        |     -> RasInfo -> BitMap
  251.        |
  252.        V
  253.     ViewPort -> ColorMap
  254.        |     -> RasInfo -> BitMap
  255.        |          |
  256.        |          V
  257.        |        RasInfo -> BitMap
  258.        |
  259.        V
  260.     ViewPort -> ColorMap
  261.          -> RasInfo -> BitMap
  262.  
  263.  The View and ViewPort structures are initialised by the InitView
  264.  and InitVPort routines respectively. The routines
  265.  GetColorMap and FreeColorMap may be used to
  266.  allocate and deallocate a ColorMap structure.
  267.  
  268.  Once these structures are correctly initialised and linked to each other,
  269.  Kernel routines are used to generate a display from them:
  270.  - MakeVPort generates an intermediate copper list (see Copper
  271.    Graphics) for a ViewPort from a View and ViewPort structure; this
  272.    should be performed for each ViewPort which is new or whose parameters
  273.    have changed in any way;
  274.  - MrgCop generates hardware copper lists (see Copper Graphics)
  275.    for a view, using the View structure to collect all the ViewPort
  276.    intermediate copper lists and merge them together; MrgCop must be
  277.    called whenever a change occurs in any viewport parameter.
  278.  - LoadView causes the copper to execute the copper list created
  279.    by MrgCop, thus displaying the view. LoadView is generally called
  280.    immediately after MrgCop.
  281.  
  282.  As an example of the use of these routines, consider a view containing
  283.  two viewports. The first uses dual-playfield mode to scroll two bit maps
  284.  independently, the second switches back and forth slowly between two
  285.  separate pictures on different bit maps, each with its own BitMap
  286.  structure:
  287.  
  288.  - initialise and link structures;
  289.  - call MakeVPort for each ViewPort;
  290.    Loop start:
  291.  - set offsets in both RasInfo structures for first viewport;
  292.  - call MakeVPort for first viewport
  293.  - if it's time to switch pictures in the second viewport, do:
  294.  - set BitMap pointer in RasInfo to point to desired BitMap
  295.    structure
  296.  - call MakeVPort for second viewport;
  297.  - call MrgCop and LoadView;
  298.  - go back to loop start.
  299.  
  300.  
  301. I‚n‚t‚u‚i‚t‚i‚o‚n‚ ‚G‚r‚a‚p‚h‚i‚c‚s‚
  302.  This sections explains the relationship between the Intuition user
  303.  interface and the Kernel graphics described above, and how to ensure
  304.  that your programs do not destroy this interface.
  305.  
  306.  Intuition is a task which provides an interface between the user and
  307.  the operating system AmigaDOS, allowing the user to communicate his
  308.  desires to the programs using the interface via objects intended to
  309.  appear "concrete" to some extent. Intuition maintains two types of
  310.  screen memory through which the program and the user interact - the
  311.  "screen" and the "window".
  312.  
  313. S‚c‚r‚e‚e‚n‚s‚
  314.  
  315.  A screen is a viewport which can be easily controlled by the user. If
  316.  a screen has a "title bar" along the top (rendered into the screen's bit
  317.  map by Intuition) the user can pull the screen down with the mouse -
  318.  i.e. alter the vertical offset of the viewport. If there is a screen
  319.  "behind" this one (Intuition maintains a depth-arranged list of screens)
  320.  a viewport is created for it which increases in size as the first screen
  321.  is pulled lower. On the right-hand side of the title bar are two gadgets
  322.  with which the user can push the screen to the back and bring it to the
  323.  front. If the title bar of a screen is not present the user cannot move
  324.  it.
  325.  
  326.  To create a screen, a "NewScreen" structure must be initialised. It
  327.  contains information about both the viewport (e.g. graphics mode, height
  328.  and width) and bit map (e.g. height, width, depth) needed for a screen.
  329.  This structure is then used by the routine OpenScreen to
  330.  create (open) a screen. OpenScreen returns a pointer to a structure,
  331.  known as a Screen, which contains a complete ViewPort structure, a
  332.  pointer to a RastPort, a pointer to the first Window on the Screen
  333.  (see below) and various information used by Intuition to manage its
  334.  collection of Screens. The RastPort created by OpenScreen may be used
  335.  in the manner described in Graphics Rendering, with one important
  336.  caveat: since Intuition renders the Screen's title bar and menus into
  337.  the same bit map as that pointed to by the RastPort, you may overwrite
  338.  them by using the Screen's RastPort. This is quite safe, but
  339.  disconcerting to the user !
  340.  
  341.  
  342. W‚i‚n‚d‚o‚w‚s‚
  343.  
  344.  A window is a "virtual" piece of display memory which uses a rectangular
  345.  region of a Screen's bit map, but can be made to appear to the programmer
  346.  and user as though it has its own private screen memory. A window can
  347.  be set up such that when another window overlaps it, the obscured portion
  348.  is saved in an off-screen bit map and restored when that region of the
  349.  window is restored. windows (if permitted by the programmer) may be
  350.  moved, resized, depth-arranged and closed (removed), and are the most
  351.  powerful element of Intuition. Each window has associated with it a
  352.  "Layer" structure, which Intuition uses to ensure that all rendering
  353.  into a window is clipped at it boundaries, and at edges where overlaying
  354.  windows cover it. To create a window, a "NewWindow" structure must be
  355.  initialised to indicate which options, from the large number available,
  356.  the window is to have.
  357.  The routine OpenWindow is then called to create the window;
  358.  it returns the address of a "Window" structure, which contains
  359.  information about the status of the window and its environment, in
  360.  particular a pointer to the window's RastPort.
  361.  It is possible to create a window which covers an entire screen and yet
  362.  is invisible by specifying the BACKDROP and BORDERLESS flags when
  363.  creating the window. Although this might appear to have little point,
  364.  drawing to the RastPort of this window rather than that of the screen
  365.  has two advantages - any rendering outside the window (and thus the
  366.  screen) is clipped, which protects you from altering memory you haven't
  367.  allocated, and the title bar and menus cannot be overwritten.
  368.  
  369. W‚h‚a‚t‚ ‚Y‚o‚u‚ ‚C‚a‚n‚ ‚G‚e‚t‚ ‚A‚w‚a‚y‚ ‚W‚i‚t‚h‚
  370.  
  371.  It is quite safe to use most of the facilities of Kernel and Copper
  372.  graphics as long as several important points are borne in mind:
  373.  - Intuition uses a view for its display, which is accessible to the
  374.    programmer via the IntuitionBase data structure. If you alter the
  375.    viewport of your screen in such a way that a MakeVPort-MrgCop-LoadView
  376.    sequence is required to update the display, resist the temptation to
  377.    do this yourself with Intuition's view. If a screen is being moved by
  378.    the user while you are calling these routines the system will crash,
  379.    since Intuition is simultaneously doing the same to update the same
  380.    view. If you really must do this, call Forbid before and
  381.    Permit after these calls to lock out Intuition. It is far
  382.    better to use the Intuition routines MakeScreen,
  383.    RemakeDisplay and RethinkDisplay, which
  384.    perform the same operations in co-operation with Intuition;
  385.  - Rendering with a screen's RastPort is dangerous, since there is no
  386.    protection against overwriting the title bar, menus, windows or
  387.    off-screen memory. Unless there are no menus, windows or title bar
  388.    on the screen use a backdrop-borderless window instead;
  389.  - Don't make any assumptions about the position of your screen on the
  390.    Amiga's display or its visibility. This applies when using  copper
  391.    list instructions, whose positional origin bears to relation to your
  392.    screen's viewport or even the view. Using the User Copper List
  393.    mechanism adjusts copper instructions to stay in position relative
  394.    to your screen.
  395.  
  396.  
  397. C‚o‚p‚p‚e‚r‚ ‚G‚r‚a‚p‚h‚i‚c‚s‚
  398.  
  399. W‚h‚a‚t‚ ‚t‚h‚e‚ ‚C‚o‚p‚p‚e‚r‚ ‚D‚o‚e‚s‚
  400.  
  401.  The copper is a simple, fast microprocessor designed to control the
  402.  video display of the Amiga, although it can manipulate other system
  403.  hardware. It does this by modifying word-length "hardware registers",
  404.  which control the Amiga's custom chips, at times when the video beam
  405.  is at a given position on the display. These hardware registers are
  406.  mapped into the Amiga's address space, and may thus be read and written
  407.  directly by the programmer as well.
  408.  
  409.  The copper has three instructions, each of which occupies two words.
  410.  They are:
  411.  - WAIT puts the copper into an inactive state until the specified beam
  412.    position is reached, whereupon the next instruction in the copper list
  413.    (see below) is executed;
  414.  - MOVE places a data word into a hardware register;
  415.  - SKIP jumps over the next instruction in the copper list if the video
  416.    beam is already past the specified position.
  417.    Note that since the address of the current copper instruction is
  418.  itself contained in a hardware register, the MOVE instruction can
  419.  perform a jump by writing to this register.
  420.  
  421.  It is important to note that the beam origin point used by the WAIT
  422.  instruction is not the top left corner of a viewport or view, but the
  423.  point (probably off the screen) relative to which the view is positioned.
  424.  This makes it tedious to calculate beam positions, particularly when
  425.  dealing with Kernel or Intiuition displays.
  426.  
  427. D‚i‚r‚e‚c‚t‚ ‚C‚o‚p‚p‚e‚r‚ ‚P‚r‚o‚g‚r‚a‚m‚m‚i‚n‚g‚
  428.  
  429.  The program executed by the copper is termed a "copper list", and
  430.  consists of a contiguous series of MOVE, WAIT and SKIP instructions in
  431.  memory.
  432.  There may be two copper lists - the "long frame" list which is executed
  433.  while the beam is visible and an optional "short frame" list which is
  434.  executed while the beam is in flyback (i.e. returning to the top of the
  435.  screen). The addresses of theses lists are stored in hardware registers,
  436.  and are automatically loaded into the copper instruction address
  437.  register at the appropriate time so that the same lists are executed for
  438.  each video frame.
  439.  
  440.  Using a hardware copper list is very straightforward; you need to:
  441.  - allocate chip memory for your list;
  442.  - write your instructions;
  443.  - set the copper list hardware registers.
  444.  
  445. U‚s‚e‚r‚ ‚C‚o‚p‚p‚e‚r‚ ‚P‚r‚o‚g‚r‚a‚m‚m‚i‚n‚g‚
  446.  
  447.  Although the copper can be programmed at the hardware level as described
  448.  so far, the user must take complete control of the display. To allow
  449.  copper lists to be integrated with existing Kernel or Intuition displays,
  450.  the data structures CopIns, UCopList and CopList
  451.  are provided. The copper actions specified using these structures are
  452.  made relative to a specified viewport rather than the whole display,
  453.  which allows them to be properly co-ordinated with Kernel or Intuition
  454.  graphics.
  455.  
  456.  The CopIns data structure corresponds to a hardware copper instruction,
  457.  and is termed an "intermediate copper instruction". It contains the
  458.  following data:
  459.  - an opcode to mark this CopIns as a MOVE or WAIT instruction or the
  460.    end of a CopIns block (see below). SKIP instructions are not allowed;
  461.  - Vertical and Horizontal beam positions (for a WAIT) or a hardware
  462.    register address and data (for a MOVE).
  463.  The CopList structure points to a contiguous block of CopIns structures
  464.  (and specifies how many may be in the block), and to the next CopList
  465.  if it exists. The UCopList structure, which is pointed to by a ViewPort,
  466.  likewise points to a CopList and the next UCopList.
  467.  
  468.  The structure of a complex user copper list may thus be:
  469.  
  470. ViewPort
  471.    |
  472.    V
  473. UCopList -> CopList -> CopIns,CopIns,CopIns... (adjacent)
  474.    |           |
  475.    |           V
  476.    |        CopList -> CopIns,CopIns,CopIns...
  477.    V
  478. UCopList -> CopList -> CopIns,CopIns,CopIns...
  479.  
  480.  Fortunately for the user, Kernel routines are provided to create and
  481.  manage these structures:
  482.  - CMOVE and CWAIT add a MOVE or WAIT instruction to a specified UCopList;
  483.  - CEND adds a WAIT instruction to a UCopList with a beam position which
  484.    cannot be attained, thus effectively "stopping" the copper.The user must
  485.    provide a UCopList structure, but CMOVE, CWAIT and CEND handle the
  486.    creation and manipulation of the CopList and UCopList structures. When
  487.    the intermediate copper list is no longer needed, it may be deallocated
  488.    with a call to the routine FreeVPortCopLists.
  489.  
  490.  Once the user copper list is complete, MrgCop is used to created a
  491.  hardware copper list for the view from the intermediate copper lists of
  492.  each viewport, which include the user copper lists and those created by
  493.  MakeVPort. MrgCop creates a cprlist structure which points to a
  494.  hardware copper list. This list, which is pointed to by the View
  495.  structure, is used by LoadView to set the appropriate hardware registers.
  496.  
  497. D‚i‚r‚e‚c‚t‚ ‚v‚s‚ ‚U‚s‚e‚r‚ ‚C‚o‚p‚p‚e‚r‚ ‚P‚r‚o‚g‚r‚a‚m‚m‚i‚n‚g‚
  498.  
  499.  The major advantage of direct programming over user programming is of
  500.  speed and efficiency - the creation and deallocation of a user copper
  501.  list take time, as does the execution of MrgCop. Thus a game, where
  502.  speed is the major consideration, might use direct copper programming
  503.  even though more work is required of the programmer to set up the list.
  504.  On the other hand, if the copper list is to be executed within a Kernel
  505.  or Intuition display, the user programming approach must be used.
  506.  
  507.  
  508. A‚p‚p‚e‚n‚d‚i‚c‚e‚s‚
  509.  
  510. A‚p‚p‚e‚n‚d‚i‚x‚ ‚A‚ ‚-‚
  511.  ‚B‚a‚s‚i‚c‚ ‚C‚o‚n‚c‚e‚p‚t‚s‚
  512.  
  513.  DATA STRUCTURE (or Structure): a group of data items which is known by a
  514.  collective name. The address of the structure is the same as the address
  515.  of its first field;
  516.  FIELD or ITEM: An element of a data structure;
  517.  POINTER: the address of another object, generally a data structure;
  518.  "POINTS TO" - if one structure points to another, one of its fields is
  519.  a pointer to that structure.
  520.  
  521. A‚p‚p‚e‚n‚d‚i‚x‚ ‚B
  522.  ‚ ‚-‚ ‚I‚m‚p‚o‚r‚t‚a‚n‚t‚ ‚K‚e‚r‚n‚e‚l‚ ‚R‚o‚u‚t‚i‚n‚e‚s‚
  523.  ƒ(‚d‚i‚s‚p‚l‚a‚y‚ ‚o‚n‚l‚y‚)‚
  524.  
  525. AllocMem: Allocates a block of memory whose size is specified  in
  526.  bytes, returning the address of the block. The user specifies whether
  527.  FAST or CHIP memory is desired.
  528. AllocRaster: As for AllocMem, except that the size of the bit
  529.  map (in pixels height and width) is given. The memory is allocated from
  530.  CHIP ram.
  531. CloseScreen: Closes an Intuition screen, deallocating all
  532.  structures associated with the screen's viewport. Calls RemakeDisplay to
  533.  rebuild the Intuition display.
  534. CloseWindow: Closes an Intuition window.
  535. CopperListInit: Initialises a UCopList structure.
  536. FreeColorMap: Deallocates a ColorMap structure and its
  537.  associated color table (viewport palette).
  538. FreeCprList: Deallocates a cprlist structure and hardware
  539.  copper list (normally created by MrgCop).
  540. FreeMem: Frees a block of memory whose size in bytes and starting
  541.  address is given.
  542. FreeRaster: As for FreeMem, except that bit map dimensions are
  543.  given to specify the block size.
  544. GetColorMap: Allocates and initialises a ColorMap structure
  545.  and color table, whose size is specified.
  546. InitBitMap: Initialises a BitMap structure.
  547. InitRastPort: Initialises a RastPort structure.
  548. InitVPort: Initialises a ViewPort structure.
  549. InitView: Initialises a View structure. Note that the dxOffset
  550.  and dyOffset fields are set to the DEFAULT Preferences values, not the
  551.  current ones.
  552. LoadRGB4: Copies an array of colour values into a viewport's
  553.  color table, and then calls MakeVPort, MrgCop and LoadView to update the
  554.  colours on the display.
  555. LoadView: Sets the hardware registers COP1LCx and COP2LCx (two
  556.  registers each) to the start of the hardware copper lists created by
  557.  MrgCop.
  558. MakeScreen: Calls MakeVPort for the viewport of an Intuition
  559.  screen, ensuring that the call does not clash with Intuition's own
  560.  manipulation of the viewport.
  561. MakeVPort: Creates an intermediate copper list from data in the
  562.  ViewPort structure and the ColorMap and RasInfo structures it points to.
  563.  The list contains instructions to set the colour, graphics mode and bit
  564.  plane hardware registers, among others. The address of the CopList
  565.  structure describing the list is placed in the dspIns pointer of the
  566.  ViewPort; if dspIns is not zero at the time MakeVPort is called (i.e.
  567.  there is already a dspIns list for this viewport) the copper list it
  568.  points to is deallocated.
  569. MrgCop: Merges the intermediate copper lists of each viewport in
  570.  the specified view into one hardware list, adjusting the beam position
  571.  specified in each WAIT instruction so that it occurs at the correct
  572.  position relative to the viewport's desired position on the display.
  573.  MrgCop also creates a cprlist structure which points to the hardware
  574.  list. The address of the cprlist structure is stored in the LOFCprList
  575.  field of the View structure (MrgCop does not create a short form copper
  576.  list). As for MakeVPort, if LOFCprList is non-zero the current cprlist
  577.  and hardware list will be deallocated before the new list is created.
  578. OpenScreen: Creates an Intuition screen. Allocates a Screen
  579.  structure (which contains a ViewPort structure), a RastPort, and all
  580.  other structures required by the viewport. Calls RemakeDisplay to
  581.  rebuild the Intuition Display.
  582. OpenWindow: Creates an Intuition window on the specified
  583.  screen, allocating a Window structure, a RastPort and other structures
  584.  required for Intuition's management of the window.
  585. RemakeDisplay: Rebuilds the entire Intuition display. Calls
  586.  MakeScreen for ALL screens, and then calls RethinkDisplay.
  587. RethinkDisplay: Determines the position and size of each
  588.  Intuition screen's viewport on the display, updating the appropriate
  589.  fields in the ViewPort structure contained in each Screen structure.
  590.  Then calls MrgCop and LoadView to update the Intuition display
  591.  accordingly.
  592. ScrollVPort: Moves the position of a bit map within a viewport
  593.  by altering the offset fields in the RasInfo pointed to by the ViewPort
  594.  by the x and y values specified, and then calling MakeVPort, MrgCop and
  595.  LoadView to update the display.
  596. SetRGB4: As for LoadRGB4, except that only specified colour is
  597.  altered.
  598.  
  599.  ^^^^^^^^^^^^^^^^^^^^^^^^ END OF GFX_PROG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  600.  
  601.  
  602.